package com.zzyl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ResourceDto;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.ResourceVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description ResourceController
 * @Author Lwj
 * @Date 2024-09-01-15:33
 */
@RestController
@RequestMapping("/resource")
@Slf4j
@Api(tags = "资源管理")
public class ResourceController {
    @Autowired
    private ResourceService resourceService;

    /**
     * 资源列表
     *
     * @param resourceDto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "资源列表", notes = "资源列表")
    @ApiImplicitParam(name = "resourceDto", value = "资源DTO对象", required = true, dataType = "ResourceDto")
    public ResponseResult<List<ResourceVo>> resourceList(@RequestBody ResourceDto resourceDto) {
        log.info("资源列表{}", resourceDto);
        List<ResourceVo> resourceVo = resourceService.findResourceList(resourceDto);
        return ResponseResult.success(resourceVo);
    }

    /**
     * 资源树形
     *
     * @param resourceDto
     * @return
     */
    @PostMapping("/tree")
    @ApiOperation(value = "资源树形", notes = "资源树形")
    @ApiImplicitParam(name = "resourceDto", value = "资源DTO对象", required = true, dataType = "ResourceDto")
    @ApiOperationSupport(includeParameters = {"resourceDto.label"})
    public ResponseResult<TreeVo> resourceTreeVo(@RequestBody ResourceDto resourceDto) {
        TreeVo treeVo = resourceService.resourceTreeVo(resourceDto);
        return ResponseResult.success(treeVo);
    }

    /**
     * 添加部门
     *
     * @param resourceDto
     * @return
     */
    @PutMapping
    @ApiOperation(value = "资源添加", notes = "资源添加")
    @ApiImplicitParam(name = "resourceDto", value = "资源DTO对象", required = true, dataType = "ResourceDto")
    @ApiOperationSupport(includeParameters = {"resourceDto.dataState"
            , "resourceDto.icon"
            , "resourceDto.parentResourceNo"
            , "resourceDto.requestPath"
            , "resourceDto.resourceName"
            , "resourceDto.resourceType"
            , "resourceDto.sortNo"})
    public ResponseResult createResource(@RequestBody ResourceDto resourceDto) {
        log.info("添加部门{}", resourceDto);
        resourceService.createResource(resourceDto);
        return ResponseResult.success();
    }

    /**
     * 资源修改
     *
     * @param resourceDto
     * @return
     */
    @PatchMapping
    @ApiOperation(value = "资源修改")
    public ResponseResult reSetresource(@RequestBody ResourceDto resourceDto) {
        log.info("资源修改{}", resourceDto);
        resourceService.reSetresource(resourceDto);
        return ResponseResult.success();
    }

    /**
     * 启用禁用
     *
     * @param resourceDto
     * @return
     */
    @PostMapping("/enable")
    @ApiOperation(value = "启用禁用")
    public ResponseResult ResetStatus(@RequestBody ResourceDto resourceDto) {
        log.info("启用禁用{}", resourceDto);
        resourceService.ResetStatus(resourceDto);
        return ResponseResult.success();
    }

    /**
     * 删除资源菜单
     * @param menuId
     * @return
     */
    @DeleteMapping("/{menuId}")
    @ApiOperation(value = "删除资源菜单")
    public ResponseResult deleteResource(@PathVariable String menuId) {
        log.info("删除资源菜单{}", menuId);
        resourceService.deleteResource(menuId);
        return ResponseResult.success();
    }

    /**
     * @return
     *  左侧菜单
     */
    /*@GetMapping("/menus")
    @ApiOperation(value = "左侧菜单", notes = "左侧菜单")
    public ResponseResult<List<MenuVo>> menus() {
        return ResponseResult.success(resourceService.menus());
    }*/

}
